package com.blrs.controller;

import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.core.page.TableDataInfo;
import com.blrs.domain.Stage;
import com.blrs.service.process.IStageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "阶段管理")
@RestController
@RequestMapping("/stage/stageInfo")
public class StageController extends BaseController {
    
    @Autowired
    private IStageService stageService;

    @ApiOperation("查询阶段列表")
    @GetMapping("/list")
    public TableDataInfo list(Stage stage) {
        startPage();
        List<Stage> list = stageService.selectStageList(stage);
        return getDataTable(list);
    }

    @ApiOperation("获取阶段详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(stageService.selectStageById(id));
    }

    @ApiOperation("新增阶段")
    @PostMapping
    public AjaxResult add(@RequestBody Stage stage) {
        return toAjax(stageService.insertStage(stage));
    }

    @ApiOperation("修改阶段")
    @PutMapping
    public AjaxResult edit(@RequestBody Stage stage) {
        return toAjax(stageService.updateStage(stage));
    }

    @ApiOperation("删除阶段")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {

        return toAjax(stageService.deleteStageByIds(ids));
    }


    @ApiOperation("直接从流程图中删除阶段")
    @DeleteMapping("/process/{ids}")
    public AjaxResult removeFromProcess(@PathVariable String[] ids) {

        return toAjax(stageService.deleteStageByIdsFromProcess(ids));
    }

    /**
     * 校验阶段名称是否唯一
     */
    @ApiOperation("校验阶段名称是否唯一")
    @PostMapping("/checkStageNameUnique")
    public AjaxResult checkStageNameUnique(@RequestBody Stage stage) {
        return success(stageService.checkStageNameUnique(stage));
    }
} 